﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MutableTranslator
{
	public partial class MultilineTextEditor : Form
	{
		string[] vals;

		public MultilineTextEditor(string title, string[] labels, string url)
		{
			InitializeComponent();
			this.Text = title;
			this.linkLabel1.Text = url;
			SetupForm(labels);
		}

		private void SetupForm(string[] labels)
		{
			if (labels.Length < 1)
				throw new ArgumentOutOfRangeException("There must be at least one label.");

			lineTableLayout.RowCount = labels.Length;
			Padding lblPadding = new Padding(0, 6, 0, 0);
			label0.Text = labels[0] + ":";
			for (int i = 1; i < labels.Length; i++)
			{
				Label lbl = new Label() { Name = "label" + i.ToString(), AutoSize = true, Padding = lblPadding, TabIndex = i * 2, Text = labels[i] + ":" };
				lineTableLayout.Controls.Add(lbl, 0, i);
				TextBox tb = new TextBox() { Dock = DockStyle.Top, Name = "textBox" + i.ToString(), TabIndex = (i * 2) + 1 };
				lineTableLayout.Controls.Add(tb, 1, i);
			}
			this.ClientSize = new Size(this.ClientSize.Width, ((textBox0.Height + lineTableLayout.Margin.Vertical) * labels.Length) + okButton.Height + mainTableLayout.Padding.Vertical + mainTableLayout.Margin.Vertical + 34);
		}

		public string[] Values
		{
			get
			{
				if (vals == null)
					vals = new string[lineTableLayout.RowCount];
				for (int i = 0; i < lineTableLayout.RowCount; i++)
					vals[i] = lineTableLayout.Controls["textBox" + i.ToString()].Text;
				return vals;
			}
			set
			{
				if (value.Length != lineTableLayout.RowCount)
					throw new ArgumentOutOfRangeException("Entered values must have same number as labels supplied to the constructor.");
				vals = value;
				for (int i = 0; i < value.Length; i++)
					lineTableLayout.Controls["textBox" + i.ToString()].Text = vals[i];
			}
		}

		private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start(linkLabel1.Text);
		}
	}
}
